package xyz.xiaomeiqiu.study.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPubSub;

import java.util.concurrent.atomic.AtomicBoolean;

public class PubOrder {
    Logger logger = LoggerFactory.getLogger(getClass());
    private JedisPool jedisPool;

    public PubOrder(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }

    public void publish(String message){
        try (Jedis jedis = jedisPool.getResource()) {
            Long publish = jedis.publish("order-queue", message);
            if(publish==1L){
                logger.info("发布消息:{}",message);
            } else {
                logger.error("发布消息失败:{}",message);
            }
        }
    }

}
